from typing import Optional

from fastapi import APIRouter, Depends
from pydantic import BaseModel

from conf import variable
from dependencies import get_current_user
from service import dcm_download

router = APIRouter(prefix=variable.CONTEXT_PATH + '/dcmlist',
                   tags=['dcmlist'],
                   dependencies=[Depends(get_current_user)])


class FindDcmDownloadListItem(BaseModel):
    keyword: Optional[str] = None
    status: str
    limit: int
    page: int


@router.post('/find_dcm_download_list')
async def find_dcm_download_list(item: FindDcmDownloadListItem):
    data_list, total = dcm_download.find_dcm_download_list(item.keyword, item.status, item.limit, item.page)
    return {'code': 0, 'msg': '', 'count': total, 'data': data_list}
